<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: TabView from Existing Markup</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>Example: TabView from Existing Markup</h1>

    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><div class="intro">
    This example shows how to create a <code>TabView</code> widget from existing HTML on the page.
</div>

<div class="example yui3-skin-sam">
<div id="demo">
    <ul>
        <li><a href="#foo">foo</a></li>
        <li><a href="#bar">bar</a></li>
        <li><a href="#baz">baz</a></li>
    </ul>
    <div>
        <div id="foo">
            <p>foo content</p>
        </div>
        <div id="bar">
            <p>bar content</p>
        </div>
        <div id="baz">
            <p>baz content</p>
        </div>
    </div>
</div>

<script type="text/javascript">
YUI().use('tabview', function(Y) {
    var tabview = new Y.TabView({srcNode:'#demo'});
    tabview.render();
});
</script>

</div>

<h2>Creating A TabView From Existing Markup</h2>

<p>A <code>TabView</code> can be created easily from existing markup, supporting a progressive enhancement approach to development.</p>

<h3>The Markup</h3>

<p>The only markup requirements are an unordered list of items and a corresponding group of divs.</p>

<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#foo&quot;&gt;foo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#bar&quot;&gt;bar&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#baz&quot;&gt;baz&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
    &lt;&#x2F;ul&gt;
    &lt;div&gt;
        &lt;div id=&quot;foo&quot;&gt;
            &lt;p&gt;foo content&lt;&#x2F;p&gt;
        &lt;&#x2F;div&gt;
        &lt;div id=&quot;bar&quot;&gt;
            &lt;p&gt;bar content&lt;&#x2F;p&gt;
        &lt;&#x2F;div&gt;
        &lt;div id=&quot;baz&quot;&gt;
            &lt;p&gt;baz content&lt;&#x2F;p&gt;
        &lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


<h3>The JavaScript</h3>

<p><code>TabView</code> extends <code>Widget</code>, and the <code>srcNode</code>
becomes the <code>contentBox</code>.  This is the
minimal requirement to create a <code>Tabview</code> instance for the markup,
and can be assigned using a selector.  Calling render enlivens the <code>TabView
</code> making it usable.</p>

<pre class="code prettyprint">var tabview = new Y.TabView({srcNode:&#x27;#demo&#x27;});
tabview.render();</pre>



<h2>Complete Example Source</h2>
<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#foo&quot;&gt;foo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#bar&quot;&gt;bar&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
        &lt;li&gt;&lt;a href=&quot;#baz&quot;&gt;baz&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
    &lt;&#x2F;ul&gt;
    &lt;div&gt;
        &lt;div id=&quot;foo&quot;&gt;
            &lt;p&gt;foo content&lt;&#x2F;p&gt;
        &lt;&#x2F;div&gt;
        &lt;div id=&quot;bar&quot;&gt;
            &lt;p&gt;bar content&lt;&#x2F;p&gt;
        &lt;&#x2F;div&gt;
        &lt;div id=&quot;baz&quot;&gt;
            &lt;p&gt;baz content&lt;&#x2F;p&gt;
        &lt;&#x2F;div&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;

&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
YUI().use(&#x27;tabview&#x27;, function(Y) {
    var tabview = new Y.TabView({srcNode:&#x27;#demo&#x27;});
    tabview.render();
});
&lt;&#x2F;script&gt;</pre>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="This example shows how to create a TabView wigdet from existing HTML.">
                                        <a href="tabview-basic.html">TabView from Existing Markup</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows how to create a TabView wigdet from JavaScript.">
                                        <a href="tabview-fromjs.html">Dynamic TabView from JavaScript</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows how to add and remove Tabs.">
                                        <a href="tabview-add-remove.html">Adding and Removing Tabs</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This example shows how to load tab content remotely using a YQL plugin.">
                                        <a href="tabview-yql.html">Loading Tab Content</a>
                                    </li>
                                
                            
                                
                            
                        </ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples That Use This Component</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                                    <li data-description="Demonstrates how to add browser history support to a TabView widget using the History Utility.">
                                        <a href="../history/history-tabview.html">History + TabView</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
